package com.example.juc.kkb.blockingqueue;

import java.util.concurrent.ArrayBlockingQueue;

public class ProdConsBlockQueueDemo {
    public static void main(String[] args) {

        MyResource myResource = new MyResource(new ArrayBlockingQueue<>(2));

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t⽣产线程启动。。。");
            try {
                myResource.myProd();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "师傅A").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t⽣产线程启动。。。");
            try {
                myResource.myProd();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "师傅B").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t⽣产线程启动。。。");
            try {
                myResource.myProd();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "师傅C").start();

        new Thread(() -> {

            System.out.println(Thread.currentThread().getName() + "\t消费线程启动。。。");
            try {
                myResource.myCons();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "====顾客A").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t消费线程启动。。。");
            try {
                myResource.myCons();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "====顾客B").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t消费线程启动。。。");
            try {
                myResource.myCons();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "====顾客C").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t消费线程启动。。。");
            try {
                myResource.myCons();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "====顾客D").start();

        myResource.stop();
    }
}